﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MAA.Entity;
using System.Resources;
using System.Globalization;
using System.Text;
using System.Security.Cryptography;

namespace MAA.Presentation
{
    public class PRLCommon
    {
        private static ResourceManager rm = new ResourceManager("MAA.Presentation.language", System.Reflection.Assembly.GetExecutingAssembly());
        private CultureInfo m_JapanCulture = new CultureInfo("ja-JP");
        private CultureInfo m_VietnameCulture = new CultureInfo("vi");

        public static string ChangeLanguageMessage(string message)
        {
            switch (message)
            {
                case Common.MESSAGE_NO_DATA_POST_SEARCH:
                    {
                        message = rm.GetString("langMESSAGE_NO_DATA_POST_SEARCH");
                    }
                    break;
                case Common.MESSAGE_NO_DATA_WAREHOUSE:
                    {
                        message = rm.GetString("langMESSAGE_NO_DATA_WAREHOUSE");
                    }
                    break;
                case Common.MESSAGE_NO_DATA_ORDER_LIST:
                    {
                        message = rm.GetString("langMESSAGE_NO_DATA_ORDER_LIST");
                    }
                    break;
                case Common.MESSAGE_NO_DATA_POST:
                    {
                        message = rm.GetString("langMESSAGE_NO_DATA_POST");
                    }
                    break;
                case Common.MESSAGE_NO_DATA_ORDER:
                    {
                        message = rm.GetString("langMESSAGE_NO_DATA_ORDER");
                    }
                    break;
                case Common.MESSAGE_ERROR_COMMON:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_COMMON");
                    }
                    break;
                case Common.MESSAGE_ERROR_SQL_FAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_SQL_FAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_CONNECT_DATABASE_FAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_CONNECT_DATABASE_FAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_SEND_EMAIL_FAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_SEND_EMAIL_FAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_NOT_LOGIN:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_NOT_LOGIN");
                    }
                    break;
                case Common.MESSAGE_ERROR_ACCOUNT_NOT_EXIST:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_ACCOUNT_NOT_EXIST");
                    }
                    break;
                case Common.MESSAGE_ERROR_WRONG_PASSWORD:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_WRONG_PASSWORD");
                    }
                    break;
                case Common.MESSAGE_ERROR_NO_CONFIRM_MAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_NO_CONFIRM_MAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_ACCOUNT_LOCKED:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_ACCOUNT_LOCKED");
                    }
                    break;
                case Common.MESSAGE_ERROR_INPUT_EMAIL_AND_PASSWORD:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_INPUT_EMAIL_AND_PASSWORD");
                    }
                    break;
                case Common.MESSAGE_ERROR_INPUT_EMAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_INPUT_EMAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_INPUT_PASSWORD:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_INPUT_PASSWORD");
                    }
                    break;
                case Common.MESSAGE_ERROR_EMAIL_EXIST:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_EMAIL_EXIST");
                    }
                    break;
                case Common.MESSAGE_ERROR_INVALID_PASSWORD:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_INVALID_PASSWORD");
                    }
                    break;
                case Common.MESSAGE_ERROR_NOT_BE_IMAGE:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_NOT_BE_IMAGE");
                    }
                    break;
                case Common.MESSAGE_ERROR_LARGE_SIZE_IMAGE:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_LARGE_SIZE_IMAGE");
                    }
                    break;
                case Common.MESSAGE_ERROR_STILL_HAVE_POST:
                    {
                        message = rm.GetString("MESSAGE_ERROR_STILL_HAVE_POST");
                    }
                    break;
                case Common.MESSAGE_ERROR_INVALID_POST_PRICE:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_INVALID_POST_PRICE");
                    }
                    break;
                case Common.MESSAGE_ERROR_INVALID_POST_AMOUNT:
                    {
                        message = rm.GetString("MESSAGE_ERROR_INVALID_POST_AMOUNT");
                    }
                    break;
                case Common.MESSAGE_ERROR_DELETE_POST_FAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_DELETE_POST_FAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_CREATE_ORDER_FAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_CREATE_ORDER_FAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_INVALID_ORDER_AMOUNT:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_INVALID_ORDER_AMOUNT");
                    }
                    break;
                case Common.MESSAGE_ERROR_INVALID_ORDER_PRICE:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_INVALID_ORDER_PRICE");
                    }
                    break;
                case Common.MESSAGE_ERROR_POST_NOT_EXIST:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_POST_NOT_EXIST");
                    }
                    break;
                case Common.MESSAGE_ERROR_DELETE_ORDER_FAIL:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_DELETE_ORDER_FAIL");
                    }
                    break;
                case Common.MESSAGE_ERROR_ORDER_NOT_EXIST:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_ORDER_NOT_EXIST");
                    }
                    break;
                case Common.MESSAGE_ERROR_NOT_ENOUGH_POST_AMOUNT:
                    {
                        message = rm.GetString("langMESSAGE_ERROR_NOT_ENOUGH_POST_AMOUNT");
                    }
                    break;
                case Common.MESSAGE_SUCCESS_REGISTER:
                    {
                        message = rm.GetString("langMESSAGE_SUCCESS_REGISTER");
                    }
                    break;
                case Common.MESSAGE_SUCCESS_CONTACT:
                    {
                        message = rm.GetString("langMESSAGE_SUCCESS_CONTACT");
                    }
                    break;
                case Common.MESSAGE_SUCCESS_CONFIRM_MAIL:
                    {
                        message = rm.GetString("langMESSAGE_SUCCESS_CONFIRM_MAIL");
                    }
                    break;
                case Common.MESSAGE_SUCCESS_CHANGE_PASS:
                    {
                        message = rm.GetString("langMESSAGE_SUCCESS_CHANGE_PASS");
                    }
                    break;
            }
            return message;
        }

        public static string ChangeLanguageStatus(string status)
        {
            switch (status)
            {
                case Common.POST_STATUS_TRADING:
                    {
                        status = rm.GetString("langProcessing");
                    }
                    break;

                case Common.POST_STATUS_COMPLETE:
                    {
                        status = rm.GetString("langSucess");
                    }
                    break;

                case Common.POST_STATUS_EXPIRED:
                    {
                        status = rm.GetString("langExpiration");
                    }
                    break;

                //case Common.ORDER_STATUS_PENDING:
                //    {
                //        status = rm.GetString("langProcessing");
                //    }
                //    break;

                case Common.ORDER_STATUS_ACCEPTED:
                    {
                        status = rm.GetString("langAccepted");
                    }
                    break;

                case Common.ORDER_STATUS_REJECTED:
                    {
                        status = rm.GetString("langReject");
                    }
                    break;
            }

            return status;
        }

        public static string Encrypt(string toEncrypt, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt);
            if (useHashing)
            {
                var hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(Encoding.UTF8.GetBytes("iloveit1208"));
            }
            else keyArray = Encoding.UTF8.GetBytes("iloveit1208");
            var tdes = new TripleDESCryptoServiceProvider
            {
                Key = keyArray,
                Mode = CipherMode.ECB,
                Padding = PaddingMode.PKCS7
            };
            ICryptoTransform cTransform = tdes.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }

        public static string Decrypt(string toDecrypt, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);
            if (useHashing)
            {
                var hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(Encoding.UTF8.GetBytes("iloveit1208"));
            }
            else keyArray = Encoding.UTF8.GetBytes("iloveit1208");
            var tdes = new TripleDESCryptoServiceProvider
            {
                Key = keyArray,
                Mode = CipherMode.ECB,
                Padding = PaddingMode.PKCS7
            };
            ICryptoTransform cTransform = tdes.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            return Encoding.UTF8.GetString(resultArray);
        } 
    }
}